#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/4/29 16:47
# @Author  : 王凯
# @File    : demo_rpc.py
# @Project : scrapy_spider
import time

import frida
from loguru import logger


def on_message(message, data):
    if message["type"] == "send":
        print("[*] {0}".format(message["payload"]))
    else:
        logger.debug(message)


# 定义Frida脚本
rpc_code = """
rpc.exports = {
    geda: function (time, device_id) {
        var enc = ''
        Java.perform(function () {
            //-----------
            // 要执行特定的函数或操作
            // console.log('time:', time, "device_id", device_id)
            let DeviceNative = Java.use("com.xunmeng.pinduoduo.secure.DeviceNative");
            const ActivityThread = Java.use("android.app.ActivityThread");
            const currentApplication = ActivityThread.currentApplication();
            const context = currentApplication.getApplicationContext();
            if (device_id) {
                enc = DeviceNative["info3"](context, time, device_id);
            } else {
                enc = DeviceNative["info2"](context, time);
            }
            // console.log('enc:' + enc)
            //-----------
        });
        return enc
    }
}
"""


def gen_anti_content(time, device_id=None):
    tt = frida.get_usb_device().attach("拼多多")
    script = tt.create_script(rpc_code)
    # script.on("message", on_message)
    script.load()
    exports = script.exports
    return exports.geda(time, device_id)


if __name__ == "__main__":
    print(gen_anti_content(time=int(time.time() * 1000), device_id="eDX37CJK"))
